package utilities;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashMap;

public class Logger {
	private static HashMap<String, PrintStream> outputs = new HashMap<String, PrintStream>();
	
	public static void addOutput(String key, String path) throws IOException{
		PrintStream ps = new PrintStream(new File(path));
		outputs.put(key, ps);
	}
	
	public static void closeOutput(String key) throws IOException {
		PrintStream toBeClosed = outputs.remove(key);
		toBeClosed.close();
	}
	
	public static void log(String s){
		if (DCUtilities.PRINT_INFO_ON_SCREEN == true){
			System.out.print(s);
		}
	}
	
	public static void log(String s, String logFileKey){
		if (DCUtilities.PRINT_LOGGED_INFO_ON_SCREEN == true){
			System.out.print(s);
		}
		PrintStream ps = outputs.get(logFileKey);
		if (ps != null){
			ps.print(s);
			ps.flush();
		}
	}
	
	public static void logln(String s){
		log(s+"\n");
	}
	
	public static void logln(String s, String logFileKey){
		log(s+"\n", logFileKey);
	}
}
